library(tidyverse)
library(readxl)
path = "Excel/700 Pivot Data.xlsx"
input = read_excel(path, range = "A2:A6")
test = read_excel(path, range = "C2:D10")
result = input %>%
separate_rows(Data, sep = ", ") %>%
separate(Data, into = c("Alphabet", "Value"), sep = "-", convert = TRUE) %>%
summarise(Value = sum(Value), .by = Alphabet) %>%
arrange(Alphabet)
r2 = result %>%
add_row(Alphabet = "TOTAL", Value = sum(result$Value))
all.equal(r2, test)
#> [1] TRUEExcel BI - Excel Challenge 700
excel-challenges
excel-formulas
🔰 Answer Expected Data Alphabet Value A-234, E-256, D-3673 A Q-897, R-1, S-87 D T-90, A-308, R-45 E

Challenge Description
🔰 Answer Expected Data Alphabet Value A-234, E-256, D-3673 A Q-897, R-1, S-87 D T-90, A-308, R-45 E
Solutions
- Logic: Read the workbook ranges needed for the challenge; Parse the packed text or string structure; Aggregate or rank the data at the required grouping level; Reshape the result into the workbook output format.
- Strengths: The reshaping step mirrors the workbook output closely instead of forcing extra post-processing.
- Areas for Improvement: The solution assumes the workbook layout and selected ranges remain stable, so any structural change in the sheet would require small adjustments.
- Gem: The last reshape turns a raw transformation into something that already looks like a report.
import pandas as pd
path = "700 Pivot Data.xlsx"
input = pd.read_excel(path, usecols="A", skiprows=1, nrows=5)
test = pd.read_excel(path, usecols="C:D", skiprows=1, nrows=9)
result = (
input["Data"]
.str.extractall(r"(\w+)-(\d+)")
.rename(columns={0: "Alphabet", 1: "Value"})
.astype({"Value": int})
.groupby("Alphabet", as_index=False)["Value"]
.sum()
)
r2 = pd.concat([result, pd.DataFrame([{"Alphabet": "TOTAL", "Value": result["Value"].sum()}])], ignore_index=True)
print(r2.equals(test)) # TrueThe Python version follows the same grouped logic and keeps the transformation explicit in a dataframe pipeline.
Difficulty Level
Medium
The individual steps are manageable, but the correct transformation pattern is not obvious from the raw data.